package cn.edu.zfc.community.dao;

import cn.edu.zfc.community.pojo.Customer;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 使用@Repository标识为Dao层Bean
 * 继承JpaRepository实现基础的增删改查功能，支持findBy方法，支持@Query
 * 继承JpaSpecificationExecutor实现范式查询
 */
@Repository
public interface CustomerDao extends JpaRepository<Customer, Long>, JpaSpecificationExecutor<Customer> {

    /**
     * 根据name查询全部Customer记录
     */
    List<Customer> findByName(String name);

    /**
     * 根据name模糊且分页查询Customer记录
     */
    Page<Customer> findByNameContaining(String name, Pageable pageable);

    /**
     * 使用@Query，根据name模糊且分页查询Customer记录
     */
    @Query("select c from Customer c where c.name like %:name%")
    Page<Customer> queryByNameLike(@Param("name") String name, Pageable pageable);
}
